package com.ruoyi.web.controller.sj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sj.domain.Collect;
import com.ruoyi.sj.service.ICollectService;
import com.ruoyi.web.core.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;

/**
 * 收藏 信息操作处理
 * 
 * @author tyc@yanyu.com
 * @date 2018-11-28
 */
@Controller
@RequestMapping("/sj/collect")
public class CollectController extends BaseController
{
    private String prefix = "sj/collect";
	
	@Autowired
	private ICollectService collectService;
	
	@RequiresPermissions("sj:collect:view")
	@GetMapping()
	public String collect()
	{
	    return prefix + "/collect";
	}
	
	/**
	 * 查询收藏列表
	 */
	@RequiresPermissions("sj:collect:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Collect collect)
	{
		startPage();
        List<Collect> list = collectService.selectCollectList(collect);
		return getDataTable(list);
	}
	
	/**
	 * 新增收藏
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存收藏
	 */
	@RequiresPermissions("sj:collect:add")
	@Log(title = "收藏", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Collect collect)
	{		
		return toAjax(collectService.insertCollect(collect));
	}

	/**
	 * 修改收藏
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Collect collect = collectService.selectCollectById(id);
		mmap.put("collect", collect);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存收藏
	 */
	@RequiresPermissions("sj:collect:edit")
	@Log(title = "收藏", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Collect collect)
	{		
		return toAjax(collectService.updateCollect(collect));
	}
	
	/**
	 * 删除收藏
	 */
	@RequiresPermissions("sj:collect:remove")
	@Log(title = "收藏", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(collectService.deleteCollectByIds(ids));
	}
	
}
